{
 "cells": [
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "# 过滤器 filter()",
   "id": "56d3f24e6af60381"
  },
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2024-10-30T03:30:39.102684Z",
     "start_time": "2024-10-30T03:30:39.099977Z"
    }
   },
   "source": [
    "name = [\"张三\", \"李斯\", \"王五\"]\n",
    "for i in name:\n",
    "    print(i.startswith(\"张\"))"
   ],
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "False\n",
      "False\n"
     ]
    }
   ],
   "execution_count": 1
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-10-30T03:49:48.832851Z",
     "start_time": "2024-10-30T03:49:48.830324Z"
    }
   },
   "cell_type": "code",
   "source": [
    "name = [\"张三\", \"李斯\", \"王五\", \"张飞\"]\n",
    "print(tuple(filter(lambda x : x.startswith(\"张\"), name)))"
   ],
   "id": "b87fac6f50530e0a",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "('张三', '张飞')\n"
     ]
    }
   ],
   "execution_count": 4
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
